package com.rowenci.iot_agriculture.mapper;

import com.rowenci.iot_agriculture.bean.Worker;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

public interface WorkerDao extends JpaRepository<Worker, Integer> {

    Worker findWorkerByName(String name);

    @Transactional
    void deleteWorkerByName(String name);

    @Transactional
    @Modifying
    @Query(value = "update Worker worker set worker.name = ?2 where worker.id = ?1")
    void updateNameById(Integer id, String name);

    @Transactional
    @Modifying
    @Query(value = "update Worker worker set worker.rfidId = ?2 where worker.id = ?1")
    void updateRfidById(Integer id, Integer rfid);

    Worker findByRfidId(Integer rfidId);
}
